<template>
  <el-button type="text" size="mini" :disabled="downDisabled" @click.stop="handleGoodsDownSort()">
    <el-icon>
      <sort-down />
    </el-icon>
  </el-button>
  <el-button type="text" size="mini" :disabled="upDisabled" @click.stop="handleGoodsUpSort()" style="margin-left:-2px;">
    <el-icon>
      <sort-up />
    </el-icon>
  </el-button>
</template>
<script>
  import {reSortMediaRelGoods} from "@/api/goods/relgoods";

  export default {
    name: "MediaGoodsResort",
    props: {
      row: {
        type: Object,
        required: true
      },
      upDisabled: {
        type: Boolean,
        default: false
      },
      downDisabled: {
        type: Boolean,
        default: false
      },
      mediaid: {
        type: Number,
        default: undefined
      }
    },
    emits: ['reloadGoodsList'],
    setup(props, context) {
      const reloadGoodsDataList = () => {
        context.emit('reloadGoodsList')
      }
      const handleGoodsDownSort = () => {
        console.log(props.row);
        reSortMediaRelGoods({mediaid: props.mediaid, goodsid: props.row.goodsid, action: 'down'}).then(response => {
          if (response.errcode == 0) {
            reloadGoodsDataList()
          }
        })
      }
      const handleGoodsUpSort = () => {
        reSortMediaRelGoods({mediaid: props.mediaid, goodsid: props.row.goodsid, action: 'up'}).then(response => {
          if (response.errcode == 0) {
            reloadGoodsDataList()
          }
        })
      }
      return {
        handleGoodsDownSort,
        handleGoodsUpSort
      }
    }
  }
</script>

<style scoped>

</style>
